

package org.soenea.doitall.domain.command;

import org.dsrg.soenea.domain.command.CommandError;
import org.dsrg.soenea.domain.command.CommandException;
import org.dsrg.soenea.domain.command.impl.Command;
import org.dsrg.soenea.domain.helper.Helper;
import org.dsrg.soenea.domain.mapper.DomainObjectNotFoundException;
import org.dsrg.soenea.uow.UoW;
import org.soenea.doitall.domain.model.invite.*;
import org.soenea.doitall.domain.model.invite.mapper.*;

public class DeclineInviteCommand extends Command {
	public DeclineInviteCommand(Helper helper) {
		super(helper);
	}

	@Override
	public void setUp() throws CommandException {
		// TODO Auto-generated method stub		
	}

	@Override
	public void process() throws CommandException {


		try {
			try {
				long invitID = Long.parseLong(helper.getRequestAttribute("id").toString());
				long userID = (Long) helper.getSessionAttribute("UserID");
				Invite invite = InviteInputMapper.findInviteByInviteID(invitID);
				invite.setStatus(-1);

				UoW.getCurrent().registerDirty(invite);
				UoW.getCurrent().commit();
				
				helper.setSessionAttribute("invites", InviteInputMapper.find(userID));
			} catch (DomainObjectNotFoundException e) {
				helper.setRequestAttribute("warning",
						"Could not find a member with that username.");
			}
		} catch (Exception e) {
			throw new CommandException(e);
		}
	}

	@Override
	public void tearDown() throws CommandError {
		// TODO Auto-generated method stub
	}
}
